package com.fast.configs;

import com.fast.configs.properties.UploadProperties;
import com.fast.pojo.req.UploadFileRequest;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author ruan cai yuan
 * @version 1.0
 * @fileName com.fast.configs.FileConfig
 * @description: TODO
 * @since 2024/6/22 2:20
 */
@Configuration
@EnableConfigurationProperties(value = UploadProperties.class)
public class FileConfig implements WebMvcConfigurer {
    @Resource
    private UploadProperties uploadProperties;

    /**
     * 静态资源的位置增加指定file日录
     * <a href="http://localhost:8000/resources/images/20240601/123.jpg">...</a>
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String[] locations = {"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/",
                //自定义的本地路径
                "file:" + uploadProperties.getStaticDir()};
        registry.addResourceHandler("/**").addResourceLocations(locations);
    }
}
